//==============================================================================
//
//  File        : mmpf_scaler.h
//  Description : INCLUDE File for the Firmware Scaler Control driver function, including LCD/TV/Win
//  Author      : Penguin Torng
//  Revision    : 1.0
//
//==============================================================================



#ifndef _MMPF_SCALER_H_
#define _MMPF_SCALER_H_

#include    "includes_fw.h"


//==============================================================================
//
//                              COMPILER OPTION
//
//==============================================================================


//==============================================================================
//
//                              CONSTANTS
//
//==============================================================================
#if (CHIP == VSN_V2)
#define TOTAL_SCALER_PATH               3

#ifndef SCALER_PATH0_MAX_WIDTH
#define	SCALER_PATH0_MAX_WIDTH	        (2304)
#endif

#ifndef SCALER_PATH1_MAX_WIDTH
#define	SCALER_PATH1_MAX_WIDTH	        (1280)
#endif

#ifndef SCALER_PATH2_MAX_WIDTH
#define	SCALER_PATH2_MAX_WIDTH	        (1280)
#endif

#ifndef LPF_MAX_WIDTH
#define	LPF_MAX_WIDTH			        (SCALER_PATH0_MAX_WIDTH)
#endif
#endif

//==============================================================================
//
//                              STRUCTURES
//
//==============================================================================

typedef enum _MMPF_SCALER_SOURCE {
    MMPF_SCALER_SOURCE_ISP = 0,
    MMPF_SCALER_SOURCE_JPG,
    MMPF_SCALER_SOURCE_GRA
} MMPF_SCALER_SOURCE;

typedef enum _MMPF_SCALER_FIT_MODE
{
    MMPF_SCALER_FITMODE_OUT = 0,
    MMPF_SCALER_FITMODE_IN
} MMPF_SCALER_FIT_MODE;

typedef enum _MMPF_SCALER_PATH
{
    MMPF_SCALER_PATH_0 = 0,
    MMPF_SCALER_PATH_1,
    MMPF_SCALER_PATH_2,
    MMPF_SCALER_PATH_MAX
} MMPF_SCALER_PATH;

typedef enum _MMPF_SCALER_LPF_SR {
    MMPF_SCALER_USE_LPF = 0,
    MMPF_SCALER_SKIP_LPF
} MMPF_SCALER_LPF_SR;

typedef enum _MMPF_SCALER_COLRMTX_MODE {
    MMPF_SCALER_COLRMTX_BT601 = 0,
    MMPF_SCALER_COLRMTX_FULLRANGE,
    MMPF_SCALER_COLRMTX_EXTEND_BT601,
    MMPF_SCALER_COLRMTX_MAX
} MMPF_SCALER_COLRMTX_MODE;

typedef struct _MMPF_SCALER_FIT_RANGE {
    MMPF_SCALER_FIT_MODE   fitmode;
    MMP_USHORT  usFitResol;
    MMP_USHORT  usInWidth;
    MMP_USHORT  usInHeight;
    MMP_USHORT  usOutWidth;
    MMP_USHORT  usOutHeight;
} MMPF_SCALER_FIT_RANGE;

typedef struct _MMPF_SCALER_GRABCONTROL {
#if (CUSTOMER == ANW)
    MMP_USHORT  usScaleNV;
    MMP_USHORT  usScaleNH;
#endif
    MMP_USHORT  usScaleN;
    MMP_USHORT  usScaleM;
    MMP_USHORT  usStartX;
    MMP_USHORT  usStartY;
    MMP_USHORT  usEndX;
    MMP_USHORT  usEndY;
} MMPF_SCALER_GRABCONTROL;

typedef enum _MMPF_SCALER_ZOOMDIRECTION
{
    MMPF_SCALER_ZOOMIN = 0,
	MMPF_SCALER_ZOOMOUT,
	MMPF_SCALER_ZOOMSTOP
} MMPF_SCALER_ZOOMDIRECTION;

typedef struct _MMPF_SCALER_ZOOM_INFO {
    MMP_USHORT                 usStepX;
    MMP_USHORT                 usStepY;
    MMP_USHORT                 usInputWidth;
    MMP_USHORT                 usInputHeight;
    MMPF_SCALER_GRABCONTROL    grabCtl;          ///< For Preview Grab Control
    MMP_USHORT                 usRangeMinN;      ///< To constrain the N-Value for zoom in and zoom out
    MMP_USHORT                 usRangeMaxN;      ///< To constrain the N-Value for zoom in and zoom out
#if (CUSTOMER == ANW)
    MMP_USHORT                 usBaseNV;
    MMP_USHORT                 usBaseNH;
#endif
    MMP_USHORT                 usBaseN;          ///< The real zoom base minimum , not floating whih zoom in and zoom out
    MMPF_SCALER_ZOOMDIRECTION  direction;
    MMP_USHORT                 usZoomRate;
} MMPF_SCALER_ZOOM_INFO;

typedef struct _MMPF_SCALER_PANTILT_INFO {
    MMP_LONG ulTargetPan,ulTargetTilt;
    MMP_LONG ulCurPan,ulCurTilt;
    MMP_USHORT usPanEnd,usTiltEnd,usStep;
    MMPF_SCALER_GRABCONTROL grabCtl;          ///< For Preview Grab Control
} MMPF_SCALER_PANTILT_INFO;


typedef enum _MMPF_SCALER_OP
{
    MMPF_SCALER_OP_FINISH = 0,
    MMPF_SCALER_OP_GOING
} MMPF_SCALER_OP;

typedef enum _MMPF_SCALER_COLORMODE
{
    MMPF_SCALER_COLOR_RGB565 = 0,
    MMPF_SCALER_COLOR_RGB888,
    MMPF_SCALER_COLOR_YUV444,
    MMPF_SCALER_COLOR_YUV422
} MMPF_SCALER_COLORMODE;

//==============================================================================
//
//                              VARIABLES
//
//==============================================================================


//==============================================================================
//
//                              FUNCTION PROTOTYPES
//
//==============================================================================
MMP_ERR MMPF_Scaler_SetEngine(MMP_BOOL bUserDefine, MMPF_SCALER_PATH pathsel,
                        MMPF_SCALER_FIT_RANGE *fitrange, MMPF_SCALER_GRABCONTROL *grabctl);

MMP_ERR MMPF_Scaler_SetLPF(MMPF_SCALER_PATH pathsel, MMPF_SCALER_FIT_RANGE *fitrange, MMPF_SCALER_GRABCONTROL *grabctl);
MMP_ERR MMPF_Scaler_SetOutputColor(MMPF_SCALER_PATH pathsel, MMP_BOOL bEnable, MMPF_SCALER_COLRMTX_MODE MatrixMode);
MMP_ERR MMPF_Scaler_SetOutputFormat(MMPF_SCALER_PATH pathsel, MMPF_SCALER_COLORMODE outcolor);
MMP_ERR MMPF_Scaler_SetZoomParams(MMPF_SCALER_PATH pathsel, MMPF_SCALER_GRABCONTROL *grabctl,
                        MMP_USHORT usInputWidth, MMP_USHORT usInputHeight, MMP_USHORT usStepX, MMP_USHORT usStepY);
MMP_ERR MMPF_Scaler_SetZoomRange(MMPF_SCALER_PATH pathsel, MMP_USHORT usZoomMin, MMP_USHORT usZoomMax);
MMP_ERR MMPF_Scaler_SetDigitalZoom(MMPF_SCALER_PATH pathsel, MMPF_SCALER_ZOOMDIRECTION zoomdir, 
                                              MMP_USHORT zoomrate, MMP_USHORT startOP);
MMP_ERR MMPF_Scaler_SetZoomOP(void);
MMPF_SCALER_ZOOM_INFO* MMPF_Scaler_GetCurInfo(MMPF_SCALER_PATH PathSel);
MMP_ERR MMPF_Scaler_GetZoomInfo(MMPF_SCALER_PATH pathsel, MMP_USHORT *usBaseN, MMP_USHORT *usCurrentN);
MMP_ERR MMPF_Scaler_GetZoomOutPos(MMPF_SCALER_PATH PathSel, MMPF_SCALER_GRABCONTROL *SetgrabCtl);
MMP_ERR MMPF_Scaler_GetScaleUpHBlanking(MMPF_SCALER_PATH pathsel, MMP_BYTE pixel_delay, MMP_ULONG *HBlanking);
MMP_ERR MMPF_Scaler_EnableDNSMP(MMPF_SCALER_PATH pathsel, MMP_BYTE bDownSample);
MMP_ERR MMPF_Scaler_SetDigitalZoomOP(MMPF_SCALER_PATH pathsel, MMPF_SCALER_ZOOMDIRECTION zoomdir, 
                                              MMP_USHORT zoomrate);

MMP_ERR MMPF_Scaler_SetPanTiltRange(MMPF_SCALER_PATH pathsel, MMP_LONG usPanMin, MMP_LONG usPanMax, MMP_LONG usTiltMin, MMP_LONG usTiltMax, MMP_USHORT usSteps);
MMPF_SCALER_PANTILT_INFO* MMPF_Scaler_GetCurPanTiltInfo(MMPF_SCALER_PATH PathSel);
MMP_ERR MMPF_Scaler_SetPanTiltOP(void);
MMP_ERR MMPF_Scaler_SetDigitalPanTilt(MMPF_SCALER_PATH pathsel, MMP_USHORT startOP);
MMP_ERR MMPF_Scaler_SetPanTiltParams(MMPF_SCALER_PATH pathsel,MMP_LONG targetPan,MMP_LONG targetTilt,MMP_USHORT steps,MMP_LONG *pan_off,MMP_LONG *tilt_off);
MMP_ERR MMPF_Scaler_SetZoomSinglePipe(MMPF_SCALER_PATH mainpipe);
MMP_ERR MMPF_Scaler_EnableZoom(MMPF_SCALER_PATH pathsel);
MMP_ERR MMPF_Scaler_GetBestFitScale(MMPF_SCALER_FIT_RANGE *fitrange,
                        MMPF_SCALER_GRABCONTROL *grabctl);
MMP_ERR MMPF_Scaler_SetEnable(MMPF_SCALER_PATH pathsel, MMP_BOOL bEnable);
MMP_ERR MMPF_Scaler_SetPath(MMPF_SCALER_SOURCE source, MMPF_SCALER_PATH pathsel);
MMP_ERR MMPF_Scaler_CheckZoomComplete(MMP_BOOL *bComplete);
MMP_ERR MMPF_Scaler_CheckPanTiltComplete(MMP_BOOL *bComplete);
MMP_ERR MMPF_Scaler_SetPixelLineDelay(MMPF_SCALER_PATH pathsel, MMP_UBYTE ubPixelDelay, MMP_UBYTE ubLineDelay);

//==============================================================================
//
//                              MACRO FUNCTIONS
//
//==============================================================================


#endif // _MMPD_SCALER_H_
